using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Champ
{
    //The Human player class stores data like name and textures.  As well as functions for interfacing with the GameController
    public class Human:Player
    {
        //Allows humans to choose sides.  1 to help, 0 for neutral, -1 to against
        public override void ChooseSide()
        {
            
            if (GamePad.GetState(whichController).Buttons.A == ButtonState.Pressed)
            {
              
                previousControllerState = GamePad.GetState(whichController);
                
            }
            if (GamePad.GetState(whichController).Buttons.B == ButtonState.Pressed)
            {
                previousControllerState = GamePad.GetState(whichController);
            }
            if (GamePad.GetState(whichController).Buttons.X == ButtonState.Pressed)
            {
                previousControllerState = GamePad.GetState(whichController);
            }

            if(GamePad.GetState(whichController).Buttons.A == ButtonState.Released &&
                previousControllerState.Buttons.A == ButtonState.Pressed)
            {
                previousControllerState = GamePad.GetState(whichController);
                side = 1;
                done = true;
            }
            if (GamePad.GetState(whichController).Buttons.B == ButtonState.Released &&
                previousControllerState.Buttons.B == ButtonState.Pressed)
            {
                side = -1;
                done = true;
            }

            if (GamePad.GetState(whichController).Buttons.X == ButtonState.Released &&
                previousControllerState.Buttons.X == ButtonState.Pressed)
            {
                side = 0;
                done = true;
            }
        }
        
        //For dealing with inventory
        public override void HandleInventory()
        {
            if(CheckInputButtons(GameController.controllerButtons.Start))
            {
                done = true;
            }
        }

        //For dealing with Loot
        public override void Looting()
        {
            if (GamePad.GetState(whichController).Buttons.A == ButtonState.Pressed)
            {
                done = true;
            } 
        }
    
        //Takes in a button and checks that it has been pushed and released
        public override bool CheckInputButtons(GameController.controllerButtons button)
        {
            switch (button)
            {
                case GameController.controllerButtons.A:
                    if (GamePad.GetState(whichController).Buttons.A == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.A == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    
                case GameController.controllerButtons.B:
                    if (GamePad.GetState(whichController).Buttons.B == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.B == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.X:
                    if (GamePad.GetState(whichController).Buttons.X == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.X == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.Y:
                    if (GamePad.GetState(whichController).Buttons.Y == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.Y == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.Start:
                    if (GamePad.GetState(whichController).Buttons.Start == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.Start == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.Back:
                    if (GamePad.GetState(whichController).Buttons.Back == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.Back == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.LBump:
                    if (GamePad.GetState(whichController).Buttons.LeftShoulder == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.LeftShoulder == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.RBump:
                    if (GamePad.GetState(whichController).Buttons.RightShoulder == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.Buttons.RightShoulder == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.DLeft:
                    if (GamePad.GetState(whichController).DPad.Left == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.DPad.Left== ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.DRight:
                    if (GamePad.GetState(whichController).DPad.Right == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.DPad.Right == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.DUp:
                    if (GamePad.GetState(whichController).DPad.Up == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.DPad.Up == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                case GameController.controllerButtons.DDown:
                    if (GamePad.GetState(whichController).DPad.Down == ButtonState.Pressed)
                    {
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                    else
                    {
                        if (previousControllerState.DPad.Down == ButtonState.Pressed)
                        {
                            previousControllerState = GamePad.GetState(whichController);
                            return true;
                        }
                        previousControllerState = GamePad.GetState(whichController);
                        return false;
                    }
                default:
                    previousControllerState = GamePad.GetState(whichController);
                    return false;
            }

        }   
    }
}